<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('basic');
	$myshop = pdo_get('jy_quanfee_shop',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	if(empty($myshop)){
		exi('还未拥有小店，移步创建！','error','set/');
	}
	$return['params']=array();
	$return['params']['pid']=0;
	$return['list']=array();
	$category=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>1,'parentid'=>0,'mid'=>0,'onepluginname'=>''),array(),'id','paixu desc');
	foreach($category as &$item){
		$item['childs']=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>1,'parentid'=>$item['id']),array(),'id','paixu desc');
	}
	$return['category']=$category;
	$return['catlevel']=2;
	$return['opencategory']=true;
	$return['myshop']=$myshop;
	$return['goodsids']=$myshop['goodsids'];
	$goodsids = explode(';',$return['goodsids']);
	$return['mygoods']=pdo_getall('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$goodsids));
	set_html('title','全部商品');
	$return['sharedata']=array(
		'title'=>$return['setting']['share_title']?'全部商品'.$return['setting']['share_title']:'全部商品-电商客',
		'desc'=>$return['setting']['share_desc']?$return['setting']['share_desc']:'电商客，一个属于自己的个人商城！',
		'link'=>custom_url('jy_weishop/goods.index/fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>ATTACHMENT_URL.$setting['share_image']
	);
	exi($return);
}
// js 获取数据
if($_RQ['op']=='getlist'){
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'status'=>1,
	);
	if(trim($_RQ['keywords'])){
		$params['title like']='%'.trim($_RQ['keywords']).'%';
	}
	if($_RQ['cid']){
		$params['ccate']=intval($_RQ['cid']);
	}
	if($_RQ['order']=='isrecommand'){
		$params['saletype likes']=array('1');
	}
	if($_RQ['order']=='isnew'){
		$params['saletype likes']=array('2');
	}
	if($_RQ['order']=='ishot'){
		$params['saletype likes']=array('3');
	}
	if($_RQ['order']=='isdiscount'){
		$params['isdiscount']=intval($_RQ['isdiscount']);
	}
	if($_RQ['order']=='issendfree'){
		$params['issendfree']=intval($_RQ['issendfree']);
	}
	if($_RQ['order']=='istime'){
		$params['istime']=intval($_RQ['istime']);
	}
	//进一步整理筛选条件，商品属性字段是否需 要调整，商品分类如何筛选，orderby如何整理
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	if($_RQ['num']){
		$psize=$_RQ['num'];
	}
	$total='';
	$fields=array('id','isbargain','title','image','price','active_plugin','active_id','salenum');
	$orderby='id desc ';
	$list=pdo_getslice('jy_weishop_goods',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='selectgoods'){
	$postdata=get_postdata();
	$id = intval($postdata['id']);
	if(!$id){
		exi('没有找到该商品，请重新选择！','error');
	}
	pdo_update('jy_quanfee_shop',array('goodsids'=>$postdata['goodsids']),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$goodsids = explode(';',$postdata['goodsids']);
	$return['mygoods']=pdo_getall('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$goodsids));
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'selectgoods'=>intval($postdata['selectgoods']),
		'selectcategory'=>intval($postdata['selectcategory']),
	);
	pdo_update('jy_quanfee_shop',$data,array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	exi('保存成功！','','index/');
}	
?>